package com.estrend.redbird

import android.content.Context
import androidx.room.RoomDatabase
import com.coder.vincent.sharp_retrofit.call_adapter.flow.FlowCallAdapterFactory
import com.king.frame.mvvmframe.config.AppliesOptions
import com.king.frame.mvvmframe.config.FrameConfigModule
import com.king.frame.mvvmframe.di.module.ConfigModule
import com.prestamo.go.android.http.EncryptInterceptor
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

class AppConfigModule:FrameConfigModule() {
    override fun applyOptions(context: Context, builder: ConfigModule.Builder) {
        builder.baseUrl(Constants.BASE_URL)
            .retrofitOptions(object : AppliesOptions.RetrofitOptions{
            override fun applyOptions(builder: Retrofit.Builder) {
                builder.baseUrl(Constants.BASE_URL)
                    .addConverterFactory(GsonConverterFactory.create())
                    .addCallAdapterFactory(FlowCallAdapterFactory.create())
                    .build()
            }

        }).okHttpClientOptions(object : AppliesOptions.OkHttpClientOptions{
                override fun applyOptions(builder: OkHttpClient.Builder) {
                    builder.connectTimeout(60,TimeUnit.SECONDS)
                        .readTimeout(60,TimeUnit.SECONDS)
                        .writeTimeout(60,TimeUnit.SECONDS)
                        .addInterceptor(EncryptInterceptor())
                        .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))

                }

            }).roomDatabaseOptions(object :AppliesOptions.RoomDatabaseOptions{
                override fun applyOptions(builder: RoomDatabase.Builder<out RoomDatabase>) {
                    builder.fallbackToDestructiveMigration()
                }

            })
    }
}